#include <stdio.h>
#include <fstream>
#include <string>
#include <vector>

using std::fstream;
using std::endl;
using std::ios;
using std::max;
using std::string;
using std::vector;

class BigInteger{
	vector<long> a;

	public:
		BigInteger(){};
		BigInteger(const string &);
		BigInteger(long);

		BigInteger operator+ (const BigInteger &) const;
		BigInteger operator- (const BigInteger &) const;
		BigInteger& operator= (const BigInteger &);
		BigInteger operator* (const BigInteger &) const;
		BigInteger operator- ();
		bool lessBA (const BigInteger &) const;
		bool operator< (const BigInteger &) const;
		bool operator> (const BigInteger &) const;
		bool operator<= (const BigInteger &) const;
		bool operator>= (const BigInteger &) const;
		bool operator== (const BigInteger &) const;
		bool operator!= (const BigInteger &) const;
		string toString() const;
};

         BigInteger::BigInteger(const string & s){
			a.resize(0);
			 
			int f = 0;
			if (s[0] == '-')
			{
				a.push_back(-1);
				f = 1;
			}	
			else
			{
				a.push_back(1);
				if (s[0] == '+')f = 1;
			}

			int len = s.length();

			for (int i = len - 1; i >= f; --i)
			{
				a.push_back(s[i] - '0');		
			}
		}

		BigInteger::BigInteger (long x)
		{
			a.resize(0);

			if (x < 0)
			{
				a.push_back(-1);
			}
			else
			{
				a.push_back(1);
			}

			if (x == 0)
			{
				a.push_back(0);
				return;
			}

			x = abs(x);
			while (x > 0)
			{
				a.push_back(x % 10);
				x /= 10;
			}
		}

		BigInteger& BigInteger::operator= (const BigInteger & x)
		{
			a.resize(x.a.size());
			
			int len = a.size();

			for (int i = 0; i < len; ++i)
			{
				a[i] = x.a[i];
			}

			return (*this);
		}

		BigInteger BigInteger::operator+ (const BigInteger & x) const
		{
			BigInteger temp;
			temp.a.resize(1);

			if (a[0] + x.a[0] == 0)
			{
				temp = x;
				temp.a[0] = a[0];
				return *this - temp;
			}

			int carry = 0;
			for (int i = 1; i < max((int)a.size(), (int)x.a.size()) || carry; ++i)
			{
				temp.a.push_back(carry + (i < (int)a.size() ? a[i] : 0) + (i < (int)x.a.size() ? x.a[i] : 0));

				carry = temp.a[i] / 10;
				temp.a[i] = temp.a[i] % 10;
			}

			temp.a[0] = (a[0] + x.a[0]) / 2;

			return temp;
		}

		BigInteger BigInteger::operator- (const BigInteger & x) const
		{
			BigInteger temp;

			temp.a.resize(1);

			if (a[0] + x.a[0] == 0)
			{
				temp = x;
				temp.a[0] = a[0];
				return *this + temp;
			}

			int carry = 0;
			int sign = a[0];

			if ((*this).lessBA(x))
			{
				temp.a.resize(x.a.size());
				for (int i = 1; i < (int)x.a.size(); ++i)
				{
					temp.a[i] = x.a[i] - carry - (i < (int)a.size() ? a[i] : 0);
					carry = temp.a[i] < 0;
					if (carry) temp.a[i] += 10;
				}
				while (temp.a.size() > 2 && temp.a.back() == 0)
				{
					temp.a.pop_back();
				}

				sign *= -1;
			}
			else
			{
				temp.a.resize(a.size());
				for (int i = 1; i < (int)a.size(); ++i)
				{
					temp.a[i] = a[i] - carry - (i < (int)x.a.size() ? x.a[i] : 0);
					carry = temp.a[i] < 0;
					if (carry) temp.a[i] += 10;
				}
				while (temp.a.size() > 2 && temp.a.back() == 0)
				{
					temp.a.pop_back();
				}
			}

			temp.a[0] = sign;

			return temp;
		}

		BigInteger BigInteger::operator* (const BigInteger & x) const
		{
			BigInteger temp;

			temp.a.resize(a.size() + x.a.size());
			for (int i = 1; i < (int)a.size(); ++i)
			{
				for (int j = 1, carry = 0; j < (int)x.a.size() || carry; j++)
				{
					int cur = temp.a[i + j - 1] + a[i] * (j < (int)x.a.size() ? x.a[j] : 0) + carry;
					temp.a[i + j - 1] = cur % 10;
					carry = cur / 10;
				}
			}

			while (temp.a.size() > 2 && temp.a.back() == 0)
				temp.a.pop_back();

			temp.a[0] = a[0] * x.a[0];

			return temp;
		}

		bool BigInteger::lessBA(const BigInteger & x) const
		{
			int sa = a.size();
			int sxa = x.a.size();

			if ((sa - sxa) > 0)
			{
				return false;
			}
			
			if ((sa - sxa) < 0)
			{
				return true;
			}

			int f = 1;
			int z = 0;
			for (int i = a.size() - 1; i >= 1; --i)
			{
				if (x.a[i] > a[i])
				{
					z = 1;
					break;
				}
				if (x.a[i] < a[i])
				{
					z = -1;
					break;
				}
			}

			if (f * z > 0)
				return true;
			else 
				return false;
		}

		bool BigInteger::operator< (const BigInteger & x) const
		{
			if (a[0] > x.a[0])return false;
			if (a[0] < x.a[0])return true;

			if (a[0] > 0)
			{
				if ((*this).lessBA(x))return true;
				else return false;
			}
			
			if ((*this).lessBA(x))return false;
				else return true;
		}

		bool BigInteger::operator> (const BigInteger & x) const
		{
			return (x < *this);
		}

		bool BigInteger::operator<= (const BigInteger & x) const
		{
			return !(*this > x);
		}

		bool BigInteger::operator>= (const BigInteger & x) const
		{
			return !(*this < x);
		}

		bool BigInteger::operator== (const BigInteger & x) const
		{
			return !((x < *this) || (*this < x));
		}

		bool BigInteger::operator!= (const BigInteger & x) const
		{
			return !(*this == x);
		}

		string BigInteger::toString() const
		{
			string temp = "";

			if (a[0] == -1)temp = "-";

			for (int i = (int)a.size() - 1; i > 0; --i)
			{
				temp = temp + (char)('0' + a[i]);
			}

			return temp;
		}

		BigInteger BigInteger::operator- ()
		{
			BigInteger temp;

			temp.a.resize(a.size());

			for (int i = 0; i < (int)a.size(); i++)
			{
				temp.a[i] = a[i];
			}

			temp.a[0] *= -1;

			return temp;
		}

class Polynom{
	BigInteger a[31];

	public:
		Polynom(const string& s);
		BigInteger getans(BigInteger x);
};

		Polynom::Polynom(const string & s)
		{
			BigInteger null("0");
			for (int i = 0; i < 31; i++)
			{
				a[i] = null;
			}

			int len = s.length();
		
			int i = 0;
			while (i < len)
			{
				string t = "";
				while (s[i] != '*')
				{
					t += s[i];
					++i;
				}

				BigInteger temp(t);

				i += 3;
				int power = 0;
				while (i < len && (s[i] >= '0' && s[i] <= '9'))
				{
					power = power * 10 + (s[i] - '0');
					++i;
				}
				
				a[power] = a[power] + temp;
			}
		}

		BigInteger Polynom::getans(BigInteger x)
		{
			BigInteger ans = a[30];

			for (int i = 29; i >= 0; i--)
			{
				ans = ans * x;
				ans = ans + a[i];
			}

			return ans;
		}

int main()
{
	_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
	
	fstream in("in.txt", ios::in);
	fstream out("out.txt", ios::out);

	/*
	BigInteger b("99999");
	out << b.toString() << endl;

	BigInteger c("-99999");
	out << c.toString() << endl;

	BigInteger d = - b - c;

	out << d.toString() << endl;
	*/
	
	string pol;
	string x;

	getline(in, pol);
	getline(in, x);
	
	//out << pol;

	Polynom p(pol);

	BigInteger X(x);

	BigInteger ans = p.getans(X);
	
	out << ans.toString() <<endl;

	return 0;
}